$(function() {
		
	// 定义列
	var columns = [
		{
				field : 'no',
				title : '序号',
				align : 'left',
				formatter : function(value, row, index) {
					return index + 1;
				}
		},
		{
				field : 'orderCode',
				title : '订单评价信息',
				align : 'center',
				formatter : function(value, row, index) {
					var evaluatioDetailBuf = "";
					$.each(row.evaluationDetailArray, function(i, evaluation){
						//评论图片
						var fileImageList = evaluation.filePath.split(",");
						var imgs = "";
						$.each(fileImageList, function(imgIndex, evaluationImgPath){
							if (evaluationImgPath != "") {								
								imgs += "<a rel='evaluationImg' href='" + imgRootURL+evaluationImgPath + "'>" +
										"	<img style='width:48px;height:48px;border:1px solid #e8e8e8;' src='"+imgRootURL+evaluationImgPath+"?x-oss-process=image/resize,h_60/format,png'/>" +
										"</a>";
							}
						});
						var star = "";
						for (var i = 0; i < 5; i++) {
							if (i < evaluation.score) {
								star += "<img src='"+rootPath+"/statics/images/star-on.png' alt='"+(i+1)+"'>";
							} else {
								star += "<img src='"+rootPath+"/statics/images/star-off.png' alt='"+(i+1)+"'>";
							}
						}
						//商品评论信息
						evaluatioDetailBuf+="" +
						"<tr>" +
							"<td style='width:50px;text-align:center;'>" +
								"<a rel='productImg' href='"+imgRootURL+evaluation.productImg+"'>" +
									"<img style='float:left;width:48px;height:48px;border:1px solid #e8e8e8;' src='"+imgRootURL+evaluation.productImg+"?x-oss-process=image/resize,h_60/format,png'/>" +
								"</a>" +
							"</td>" +
							"<td style='width:300px;border-left:0px solid #fff;'>"+evaluation.productName+"</td>" +
							"<td style='width:50px;border-left:0px solid #fff;'>" +
								"<div>"+star+"</div>" +
							"</td>" +
							"<td style='width:150px;border-left:0px solid #fff;'>"+evaluation.content+"</td>" +
							"<td style='width:150px;border-left:0px solid #fff;'>"+imgs+"</td>" +
							"<td style='width:50px;border-left:0px solid #fff;'>" +
								"<a class='btn btn-danger btn-xs' href='javaScript:void(0);' onclick='doDelete(" + evaluation.id+ ")'>删除</a>" +
							"</td>" +
						"</tr>";
					});
					var result = 
						"<div class='order_row'>" +
							"<div class='order_row_info'>" +
								"<div class='order_field'>" +
									"<span>订单号："+(row.orderCode == null?'分享评论':row.orderCode)+"</span>" +
									"<span>评价时间："+row.createTimeStr+"</span>" +
									"<span>客户名称："+row.userName+"</span>" +
									"<span>客户级别："+row.levelName+"</span>";
					if (row.channel == "1") {
						result += "	<span>评论渠道：PC</span>";
					} else if (row.channel == "2") {
						result += "	<span>评论渠道：微信</span>";
					}
					result += 	"</div>" +
							"</div>" +
							"<div class='order_separator'></div>"+
							"<div>" +
							"	<table class='evaluation_detail_table'>" +
								evaluatioDetailBuf+
							"	</table>" +
							"</div>"
						"</div>";
					return result;
				}
		},];
			
			
	// 定义查询回调函数（查询参数在此设置）
	var queryParams = function(params) {
	
		var orderCode =  $("#orderCode").val()
		var productCode =  $("#productCode").val()
		var productName =  $("#productName").val()
		var score =  $("#score").val()
		var content =  $("#content").val()
		var userName =  $("#userName").val()
		var channel =  $("#channel").val()
		
		return {
			rows : params.limit, // 页面大小
			page : params.pageNumber, // 页码
			orderCode : orderCode,
			productCode : productCode,
			productName : productName,
			score : score,
			content : content,
			userName : userName,
			channel : channel
		};
	};
	
	var url = rootPath + "/orderEvaluation/listOrderEvaluationPage"; // 请求json数据的服务器地址
	sys.initTable('orderEvaluationTable', {
		url : url,
		queryParams : queryParams,
		columns : columns,
		striped : true,
		clickToSelect : true,
		onLoadSuccess : function() {
            initFancyBoxImg("productImg");
            initFancyBoxImg("evaluationImg");
		}
	});

	// 查询
	$('#btnQuery').on('click', function() {
		sys.reloadTable('orderEvaluationTable');
	});
	
	// 清空
	$('#btnClear').on('click', function() {
		$("#orderCode").val("");
		$("#productCode").val("");
		$("#productName").val("");
//		$("#score").val("");
		$("#content").val("");
		$("#userName").val("");
//		$("#channel").val("");
		$('.selectpicker').selectpicker('val', '');
	});

});

/**
 * 删除商品
 * 
 * @Description do-something
 * @author xu_cc
 * @date 创建时间：2017年9月6日 上午1:31:21
 * @param id
 */
function doDelete(id) {
	showConfirm("评论删除后不可恢复，确定要删除该商品评论吗？", function() {
		$.ajax({
			url : rootPath + "/orderEvaluation/doDelEvaluation",
			type : "post",
			async : false,
			dataType : 'json',
			data : {
				id : id
			},
			success : function(json) {
				if (json.code == '1') {
					showSuccess(json.msg, function() {
						sys.reloadTable('orderEvaluationTable');
					});
				} else {
					showErr(json.msg);
				}
			}
		});
	});
}